import MySQLdb

# err_codes

R_OK    = 0
R_ERROR = 1

class mod_account( ):

  def __init__( self ):
    self.cc = MySQLdb.connect( '', 'pentabion', 'secret', 'db', unix_socket='/var/lib/mysql/mysql.sock' )
    self.cc.query( 'set names utf8' )
    self.cc.query( 'set wait_timeout = 36600' )

  def do_login( self, authContext, args ): # login, passwd
    if args.__class__() == [] and len( args ) == 2:
      self.cc.query( 'select id from tblusers where login = "%s" and passwd = md5( "%s" )' % ( args[0], args[1] ) )
      res = self.cc.store_result()
  
      if res.num_rows() > 0L:
        row = res.fetch_row()
        return ( R_OK, [row[0][0]] )
  
      else:
        return ( R_ERROR, [ {'errcode':15, 'errdesc':'Entry not found'} ] )
  
    else:
      return ( R_ERROR, [ {'errcode':10, 'errdesc':'Wrong argv count'} ] )
  
  def do_logout( self, authContext, args ): # login
    return ( R_OK, [] )
